package com.ymatou.iapi.godfreightmgr.testcase;

import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreightmgr.parameter.GetCollectionGoodsAddressListBean;
import com.ymatou.iapi.godfreightmgr.service.GetCollectionGoodsAddressListCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

/**
 * 自提点列表 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetCollectionGoodsAddressList {
	private static GetCollectionGoodsAddressListBean getcollectiongoodsaddresslistBean;
	private static GetCollectionGoodsAddressListCall getcollectiongoodsaddresslistCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("自提点列表");
	}

	@Before
	public void caseUp() {
		getcollectiongoodsaddresslistBean = new GetCollectionGoodsAddressListBean();
		getcollectiongoodsaddresslistCall = new GetCollectionGoodsAddressListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcollectiongoodsaddresslistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_001() {
		Logger.start(true, "查询自提点列表成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);

			Map<Integer, CreateCollectionGoodsAddressBean> m = new HashMap<Integer, CreateCollectionGoodsAddressBean>();
			for (int i = 0; i < 2; i++) {
				// 添加一个自提地址
				CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
						.initCreateCollectionGoodsAddressBean(mchId_channl);
				int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
				m.put(addressId, createcollectiongoodsaddressBean);
			}
			getcollectiongoodsaddresslistBean.setKeywords(null);
			getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(20);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("200", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
			Logger.verifyEquals(2, getcollectiongoodsaddresslistCall.gettotalNum(), "验证size");
			getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().forEach(c -> {
				CreateCollectionGoodsAddressBean c2 = m.get(c.getAddressId());
				Logger.verifyEquals(c.getAddressName(), c2.getAddressName(), "验证AddressName");
				Logger.verifyEquals(c.getAddressPic(), c2.getAddressPic(), "验证AddressPic");
				Logger.verifyEquals(c.getAddressType(), c2.getAddressType(), "验证AddressType");
				Logger.verifyEquals(c.getAreaCode(), c2.getAreaCode(), "验证AreaCode");
				Logger.verifyEquals(c.getBaseAddress(), c2.getBaseAddress(), "验证BaseAddress");
				Logger.verifyEquals(c.getDetailAddress(), c2.getDetailAddress(), "验证DetailAddress");
				Logger.verifyEquals(c.getMobile(), c2.getMobile(), "验证Mobile");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_002() {
		Logger.start(true, "不输入sellerid失败");
		try {
			getcollectiongoodsaddresslistBean.setKeywords(null);
			getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(20);
//	            getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("400", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_003() {
		Logger.start(true, "不输入pageindex失败");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			// 添加一个自提地址
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
					.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			Map<Integer, CreateCollectionGoodsAddressBean> m = new HashMap<Integer, CreateCollectionGoodsAddressBean>();
			m.put(addressId, createcollectiongoodsaddressBean);
			getcollectiongoodsaddresslistBean.setKeywords(null);
//            getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(20);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("400", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_004() {
		Logger.start(true, "不输入pagesize默认20");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			// 添加一个自提地址
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
					.initCreateCollectionGoodsAddressBean(mchId_channl);
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			Map<Integer, CreateCollectionGoodsAddressBean> m = new HashMap<Integer, CreateCollectionGoodsAddressBean>();
			m.put(addressId, createcollectiongoodsaddressBean);
			getcollectiongoodsaddresslistBean.setKeywords(null);
			getcollectiongoodsaddresslistBean.setPageIndex(1);
//            getcollectiongoodsaddresslistBean.setPageSize(20);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("400", getcollectiongoodsaddresslistCall.getString("code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_005() {
		Logger.start(true, "查询自提点列表翻页查询成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
		

			Map<Integer, CreateCollectionGoodsAddressBean> m = new HashMap<Integer, CreateCollectionGoodsAddressBean>();
			for (int i = 0; i < 2; i++) {
				// 添加一个自提地址
				CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
						.initCreateCollectionGoodsAddressBean(mchId_channl);
				int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
				m.put(addressId, createcollectiongoodsaddressBean);
			}
			getcollectiongoodsaddresslistBean.setKeywords(null);
			getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(1);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("200", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
			Logger.verifyEquals(2, getcollectiongoodsaddresslistCall.gettotalNum(), "验证size");
			Logger.verifyEquals(1, getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().size(), "验证size");
			getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().forEach(c -> {
				CreateCollectionGoodsAddressBean c2 = m.get(c.getAddressId());
				Logger.verifyEquals(c.getAddressName(), c2.getAddressName(), "验证AddressName");
				Logger.verifyEquals(c.getAddressPic(), c2.getAddressPic(), "验证AddressPic");
				Logger.verifyEquals(c.getAddressType(), c2.getAddressType(), "验证AddressType");
				Logger.verifyEquals(c.getAreaCode(), c2.getAreaCode(), "验证AreaCode");
				Logger.verifyEquals(c.getBaseAddress(), c2.getBaseAddress(), "验证BaseAddress");
				Logger.verifyEquals(c.getDetailAddress(), c2.getDetailAddress(), "验证DetailAddress");
				Logger.verifyEquals(c.getMobile(), c2.getMobile(), "验证Mobile");
			});
			getcollectiongoodsaddresslistBean.setKeywords(null);
			getcollectiongoodsaddresslistBean.setPageIndex(2);
			getcollectiongoodsaddresslistBean.setPageSize(1);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("200", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
			Logger.verifyEquals(2, getcollectiongoodsaddresslistCall.gettotalNum(), "验证size");
			Logger.verifyEquals(1, getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().size(), "验证size");
			getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().forEach(c -> {
				CreateCollectionGoodsAddressBean c2 = m.get(c.getAddressId());
				Logger.verifyEquals(c.getAddressName(), c2.getAddressName(), "验证AddressName");
				Logger.verifyEquals(c.getAddressPic(), c2.getAddressPic(), "验证AddressPic");
				Logger.verifyEquals(c.getAddressType(), c2.getAddressType(), "验证AddressType");
				Logger.verifyEquals(c.getAreaCode(), c2.getAreaCode(), "验证AreaCode");
				Logger.verifyEquals(c.getBaseAddress(), c2.getBaseAddress(), "验证BaseAddress");
				Logger.verifyEquals(c.getDetailAddress(), c2.getDetailAddress(), "验证DetailAddress");
				Logger.verifyEquals(c.getMobile(), c2.getMobile(), "验证Mobile");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_006() {
		Logger.start(true, "查询自提点列表不包含已删除自提点");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
			

			Map<Integer, CreateCollectionGoodsAddressBean> m = new HashMap<Integer, CreateCollectionGoodsAddressBean>();
			for (int i = 0; i < 2; i++) {
				// 添加一个自提地址
				CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
						.initCreateCollectionGoodsAddressBean(mchId_channl);
				int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
				m.put(addressId, createcollectiongoodsaddressBean);
			}
			Integer daddressId = m.keySet().iterator().next();
			GodfreightmgrService.deletecollectiongoodsaddressCall(daddressId, mchId_channl);
			m.remove(daddressId);
			getcollectiongoodsaddresslistBean.setKeywords(null);
			getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(20);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("200", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getcollectiongoodsaddresslistCall.gettotalNum(), "验证size");
			getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().forEach(c -> {
				CreateCollectionGoodsAddressBean c2 = m.get(c.getAddressId());
				Logger.verifyEquals(c.getAddressName(), c2.getAddressName(), "验证AddressName");
				Logger.verifyEquals(c.getAddressPic(), c2.getAddressPic(), "验证AddressPic");
				Logger.verifyEquals(c.getAddressType(), c2.getAddressType(), "验证AddressType");
				Logger.verifyEquals(c.getAreaCode(), c2.getAreaCode(), "验证AreaCode");
				Logger.verifyEquals(c.getBaseAddress(), c2.getBaseAddress(), "验证BaseAddress");
				Logger.verifyEquals(c.getDetailAddress(), c2.getDetailAddress(), "验证DetailAddress");
				Logger.verifyEquals(c.getMobile(), c2.getMobile(), "验证Mobile");
			});

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_007() {
		Logger.start(true, "输入sellerid没有自提点返回空数据");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);

			getcollectiongoodsaddresslistBean.setKeywords(null);
			getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(20);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("200", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
			Logger.verifyEquals(0, getcollectiongoodsaddresslistCall.gettotalNum(), "验证size");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_008() {
		Logger.start(true, "根据keywords自提点名查询自提点列表成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);

			Map<Integer, CreateCollectionGoodsAddressBean> m = new HashMap<Integer, CreateCollectionGoodsAddressBean>();
			for (int i = 0; i < 2; i++) {
				// 添加一个自提地址
				CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
						.initCreateCollectionGoodsAddressBean(mchId_channl);
				int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
				m.put(addressId, createcollectiongoodsaddressBean);
			}
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
					.initCreateCollectionGoodsAddressBean(mchId_channl);
			createcollectiongoodsaddressBean.setAddressName("这得搜索用");
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			m.put(addressId, createcollectiongoodsaddressBean);

			getcollectiongoodsaddresslistBean.setKeywords("搜索");
			getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(20);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("200", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getcollectiongoodsaddresslistCall.gettotalNum(), "验证size");
			getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().forEach(c -> {
				CreateCollectionGoodsAddressBean c2 = m.get(c.getAddressId());
				Logger.verifyEquals(c.getAddressName(), c2.getAddressName(), "验证AddressName");
				Logger.verifyEquals(c.getAddressPic(), c2.getAddressPic(), "验证AddressPic");
				Logger.verifyEquals(c.getAddressType(), c2.getAddressType(), "验证AddressType");
				Logger.verifyEquals(c.getAreaCode(), c2.getAreaCode(), "验证AreaCode");
				Logger.verifyEquals(c.getBaseAddress(), c2.getBaseAddress(), "验证BaseAddress");
				Logger.verifyEquals(c.getDetailAddress(), c2.getDetailAddress(), "验证DetailAddress");
				Logger.verifyEquals(c.getMobile(), c2.getMobile(), "验证Mobile");
			});

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetCollectionGoodsAddressList_009() {
		Logger.start(true, "根据keywords地址查询自提点列表成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);

			Map<Integer, CreateCollectionGoodsAddressBean> m = new HashMap<Integer, CreateCollectionGoodsAddressBean>();
			for (int i = 0; i < 2; i++) {
				// 添加一个自提地址
				CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
						.initCreateCollectionGoodsAddressBean(mchId_channl);
				int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
				m.put(addressId, createcollectiongoodsaddressBean);
			}
			CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
					.initCreateCollectionGoodsAddressBean(mchId_channl);
			createcollectiongoodsaddressBean.setDetailAddress("这得搜索用-地址");
			int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
			m.put(addressId, createcollectiongoodsaddressBean);

			getcollectiongoodsaddresslistBean.setKeywords("搜索");
			getcollectiongoodsaddresslistBean.setPageIndex(1);
			getcollectiongoodsaddresslistBean.setPageSize(20);
			getcollectiongoodsaddresslistBean.setSellerId(mchId_channl);
			getcollectiongoodsaddresslistCall.setData(getcollectiongoodsaddresslistBean);
			getcollectiongoodsaddresslistCall.callService();
			Logger.verifyEquals("200", getcollectiongoodsaddresslistCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getcollectiongoodsaddresslistCall.gettotalNum(), "验证size");
			getcollectiongoodsaddresslistCall.getCollectiongoodsAddress().forEach(c -> {
				CreateCollectionGoodsAddressBean c2 = m.get(c.getAddressId());
				Logger.verifyEquals(c.getAddressName(), c2.getAddressName(), "验证AddressName");
				Logger.verifyEquals(c.getAddressPic(), c2.getAddressPic(), "验证AddressPic");
				Logger.verifyEquals(c.getAddressType(), c2.getAddressType(), "验证AddressType");
				Logger.verifyEquals(c.getAreaCode(), c2.getAreaCode(), "验证AreaCode");
				Logger.verifyEquals(c.getBaseAddress(), c2.getBaseAddress(), "验证BaseAddress");
				Logger.verifyEquals(c.getDetailAddress(), c2.getDetailAddress(), "验证DetailAddress");
				Logger.verifyEquals(c.getMobile(), c2.getMobile(), "验证Mobile");
			});

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}